'use strict';
var myApp = angular.module('myApp', [
  'ngRoute',

  'myApp.students',
  'myApp.students_add',

  'myApp.classes',
  'myApp.classes_add',

  'myApp.teachers',
  'myApp.teachers_add',

  'myApp.exam_list',
  'myApp.exam_add',
  'myApp.exam_info',
  'myApp.exam_trend',

  'myApp.homework_list',
  'myApp.homework_add',

  'myApp.comment_list',
  'myApp.comment_add',

  'myApp.version'
]);

myApp.factory('breadcrumbData', function() {
  return [{"name":"首页","url":"/"}]
});

//左侧导航
myApp.controller('menuCtrl',['$scope','breadcrumbData','$location','$http',function($scope,breadcrumbData,$location,$http) {
    var menuDataAll = [
      {
        name:"教学管理",url:"",icon:"user",show:true,
        sons:[
          {name:"成绩",url:"exam_list",icon:"user",sons:[]},
          {name:"作业",url:"homework_list",icon:"user",sons:[]},
          {name:"评价",url:"comment_list",icon:"user",sons:[]}
        ]
      },
      {
        name:"数据管理",url:"",icon:"user",show:true,
        sons:[
          {name:"学生",url:"students",icon:"user",sons:[]},
          {name:"班级",url:"classes",icon:"user",sons:["school","classes_add"]},
          {name:"教师",url:"teachers",icon:"user",sons:[]},
        ]
      },
      {
        name:"系统设置",url:"",icon:"user",show:false,
        sons:[
        ]
      },
    ];

    $scope.menus = menuDataAll;

    $scope.menusonActive = function(menu,menuson){
      menu.show = true;
      $scope.menuNow = menuson;
      breadcrumbData.length = 1;
      breadcrumbData.push({"name":menu.name});
      breadcrumbData.push({"name":menuson.name,"url":menuson.url});
    }

    $scope.logout = function(){
      $http.get('user/logout').success(function(data){
          if(!data.error ){
              kremove("id");
              kremove("name");
              window.location.href = '/';             
          }else{
              alert(data.message);
          }
      });
    } 
    
}]);

//
myApp.controller('breadcrumbCtrl', ['$scope','breadcrumbData', function($scope,breadcrumbData) { 
    $scope.breadcrumbs = breadcrumbData;
}]);

myApp.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/students', {
    templateUrl: 'views/students/students.html',
    controller: 'studentsCtrl'

  }).when('/students_add', {
    templateUrl: 'views/students/students_add.html',
    controller: 'students_addCtrl'

  }).when('/students/:id', {
    templateUrl: 'views/students/students_add.html',
    controller: 'students_addCtrl'

  //班级
  }).when('/classes', {
    templateUrl: 'views/classes/classes.html',
    controller: 'classesCtrl'

  }).when('/classes_add', {
    templateUrl: 'views/classes/classes_add.html',
    controller: 'classes_addCtrl'

  }).when('/classes_add/:id', {
    templateUrl: 'views/classes/classes_add.html',
    controller: 'classes_addCtrl'

  //老师
  }).when('/teachers', {
    templateUrl: 'views/teachers/teachers.html',
    controller: 'teachersCtrl'

  }).when('/teachers_add/:id', {
    templateUrl: 'views/teachers/teachers_add.html',
    controller: 'teachers_addCtrl'

  }).when('/teachers_add', {
    templateUrl: 'views/teachers/teachers_add.html',
    controller: 'teachers_addCtrl'

  }).when('/exam_list',{
    templateUrl: 'views/exam/exam_list.html',
    controller: 'exam_listCtrl'

  }).when('/exam_add',{
    templateUrl: 'views/exam/exam_add.html',
    controller: 'exam_addCtrl'

  }).when('/exam_info',{
    templateUrl: 'views/exam/exam_info.html',
    controller: 'exam_infoCtrl'

   }).when('/exam_trend',{
    templateUrl: 'views/exam/exam_trend.html',
    controller: 'exam_trendCtrl'

  }).when('/homework_list',{
    templateUrl: 'views/homework/homework_list.html',
    controller: 'homework_listCtrl'

  }).when('/homework_add',{
    templateUrl: 'views/homework/homework_add.html',
    controller: 'homework_addCtrl'

  }).when('/comment_list',{
  templateUrl: 'views/comment/comment_list.html',
  controller: 'comment_listCtrl'

  }).when('/comment_add',{
  templateUrl: 'views/comment/comment_add.html',
  controller: 'comment_addCtrl'

  }).otherwise({redirectTo: '/'});
}]);
